﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class Hoadon : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["User"] == null)
        {
            Response.Redirect("chuadangnhap.aspx");
        }   
        string user = Session["User"].ToString();
        connection ketnoi = new connection();
        ketnoi.Open();
        string sql = "select pm.Maphieumua,COUNT(*) + 1 as soluong, SUM(ctpm.thanhtien)as tongtien from Phieumuasanpham pm, Chitietphieumuasanpham ctpm where pm.Maphieumua = ctpm.Maphieumuasanpham  group by pm.Maphieumua";
        DataSet ds = new DataSet();
        ketnoi.return_dataset(ds, sql, "PHIEUMUA");
        sql = "  SELECT  pm.Maphieumua,sh.Tenshop,sp.Tensanpham, ctpm.soluong, ctpm.thanhtien,Case pm.trangthai when 0 then 'Chua thanh toan' else 'da thanh toan' end as tinhtrang from Phieumuasanpham pm, Chitietphieumuasanpham ctpm, Sanpham sp, Shop sh where pm.Maphieumua = ctpm.Maphieumuasanpham and ctpm.Masanpham = sp.Masanpham and sp.Mashop = sh.Mashop and pm.Username='" + user + "'";
        ketnoi.return_dataset(ds, sql, "CHITIET");
        ds.Relations.Add("myrelation",ds.Tables["PHIEUMUA"].Columns[0],ds.Tables["CHITIET"].Columns[0]);
        parent_repeater.DataSource = ds.Tables["PHIEUMUA"];
        Page.DataBind();
        ketnoi.Close();
     

    }
}